package com.task.web;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.task.dao.TaskDao;
import com.task.dao.UserDao;
import com.task.entity.Task;
import com.task.entity.User;

public class UserAction extends ActionSupport{

	private UserDao userDao;
	
	private User user;
	
	private TaskDao taskDao;
	
	Map session=null;

	public void setTaskDao(TaskDao taskDao) {
		this.taskDao = taskDao;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	//登录验证
	public String doLogin(){
		User user1=userDao.checkLogin(user);
		if(user1==null){
			return "login";			
		}
		else{
			session=ActionContext.getContext().getSession();
			session.put("LOGINED_USER", user1);
			List<Task> task0=taskDao.getTaskOfNoType();
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			String date=sdf.format(new Date());
			List<Task> task1=taskDao.getTaskByDateAndType(user1.getUserId(), date, 1,0);
			List<Task> task2=taskDao.getTaskByDateAndType(user1.getUserId(), date, 2,0);
			List<Task> task3=taskDao.getTaskByDateAndType(user1.getUserId(), date, 3,0);
			List<Task> task4=taskDao.getTaskByDateAndType(user1.getUserId(), date, 4,0);
			List<Task> futureTask=taskDao.getFuture5Tasks(user1.getUserId());
			session.put("task0", task0);
			session.put("task1", task1);
			session.put("task2", task2);
			session.put("task3", task3);
			session.put("task4", task4);
			session.put("futureTask", futureTask);
			session.put("date", date);System.out.println(date);
			return "index";		
		}
	}
}
